<?php
/**
 * Created by PhpStorm.
 * User: zhanglin02
 * Date: 2016/4/10
 * Time: 18:58
 */

namespace Admin\Controller;


class BlogController extends CommonController
{
    public function index(){
        $p = I('get.p/d,0');//当前页码
        $cid = I('get.cid/d,-1');//分类ID（0表示未分类，-1表示全部分类）
        $Blog = D('Blog');  //实例化博文模型
        $Category = D('Category'); //实例化分类模型
        //如果分类ID大于0，则去除所有子分类ID
        $cids = ($cid>0)? $Category->getSubIds($cid):$cid;
        //获取商品列表
        $data['blog'] = $Blog->getList('blog',$cids,$p);
        //防止空页被访问
        if(empty($data['blog']['data']) && $p>0){
            $this->redirect('Blog/index',array('cid'=>$cid));
        }
        //查询分类列表
        $data['category'] = $Category->getList();
        $data['cid'] = $cid;
        $data['p'] = $p;
        $this->assign($data);
        $this->display();
    }
}